<?php

namespace app\admin\validate\foods;

use app\admin\validate\Validates;

class Foods extends Validates
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */	
	protected $rule = [
        'ids|标识' => 'require|array',
        'id|标识' => 'require|integer|>:0',
        'cid|分类标识' => 'require|array',
        'title|名称' => 'length:1,10',
        'desc|菜品描述' => 'max:100',
        'img_url|图片' => 'url|checkImage|checkReal',
        'original_price|原价' => 'float',
        'price|金额' => 'require|float',
        'status|状态' => 'in:0,1',
        'start_sort_num|排序值开始范围' => 'integer|>=:0',
        'end_sort_num|排序值结束范围' => 'integer|>=:0',
        'sort_num|排序' => 'require|integer|>=:0',
        'stock|库存' => 'require|integer|>=:0',
        'pack_fee|包装费' => 'float|between:0,99'
    ];
    
    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */	
    protected $message = [];

    /**
     * 场景验证
     * @var []
     */
    protected $scene = [
        'index' => ['title','status','start_sort_num','end_sort_num'],
        'delete' => ['id'],
        'destory' => ['ids']
    ];

    /**
     * 定义新增场景验证
     * @return $this
     */
    public function sceneCreate()
    {
        return $this->only(['cid','title','desc','img_url','pack_fee','original_price','price','sort_num','status','stock'])
            ->append('title', 'require')
            ->append('status', 'require');
    }

    /**
     * 定义编辑场景验证
     * @return $this
     */
    public function sceneUpdate()
    {
        return $this->only(['cid','title','desc','img_url','pack_fee','original_price','price','sort_num','status','stock'])
            ->append('title', 'require')
            ->append('status', 'require');
    }

}
